home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* misc.c */
- /* */
- /* Random and networking functions. */
- /************************************************************************/
-
- /************************************************************************/
- /* history */
- /* */
- /* 85Aug17 HAW Fix putFLChar() to indicate errors. */
- /* 85Jul04 HAW Change configure() to accept parameters. */
- /* 85Mar21 HAW Loss of carrier is now detected for downloading of file.*/
- /* 85Mar20 HAW Add time stamp code. */
- /* 85Mar13 HAW Fix upLoad() to kill unsuccessful uploads. */
- /* 85Feb22 HAW Implement download/upload. */
- /* 85Jan21 HAW Fix tutorial() so invalid drive cannot be specified. */
- /* 85Jan21 HAW Insert function setdate() for MSDOS, modify changedate()*/
- /* 85Jan20 HAW Insert function getdate() for MSDOS, modify changedate()*/
- /* 84Aug31 HAW What's that? MS-DOS? Nooooooo!!!! */
- /* 84Jul08 HAW file_RO changed to detect R/O drives. */
- /* 84Jul03 HAW file_RO written to check .SYS files for R/O status. */
- /* 84Jun23 HAW & JLS patchDebug put under control of conditional comp. */
- /* 84Jun16 JLS & HAW Configure fixed so that ".Enter Con..." works */
- /* 84Jun10 JLS Function changedate() installed. */
- /* 84May01 HAW Starting 1.50a upgrade. */
- /* 83Mar12 CrT from msg.c */
- /* 83Mar03 CrT & SB Various bug fixes... */
- /* 83Feb27 CrT Save private mail for sender as well as recipient. */
- /* 83Feb23 Various. transmitFile() won't drop first char on WC... */
- /* 82Dec06 CrT 2.00 release. */
- /* 82Nov05 CrT Stream retrieval. Handles messages longer than MAXTEXT.*/
- /* 82Nov04 CrT Revised disk format implemented. */
- /* 82Nov03 CrT Individual history begun. General cleanup. */
- /************************************************************************/
-
- #include "ctdl.h"
-
- /************************************************************************/
- /* contents */
- /* */
- /* changeDate() allow changing of date */
- /* configure() sets terminal parameters via dialogue */
- /* crashout() crashes out of Citadel in case of bug */
- /* doCR() newline on modem and console */
- /* download() menu-level routine for WC-protocol sends*/
- /* getdate() gets date from MSDOS system clock. */
- /* patchDebug() display/patch byte */
- /* printDate() prints out date */
- /* putFLChar() readFile() -> disk file interface */
- /* putWCChar() filter[]s, readFile() to putMsgChar() */
- /* setdate() sets the date */
- /* transmitFile() send a host file, no formatting */
- /* tutorial() prints a .hlp file */
- /* upLoad() menu-level read-via-WC-protocol fn */
- /* visible() convert control chars to letters */
- /************************************************************************/
-
- /************************************************************************/
- /* External variable declarations in MISC.C */
- /************************************************************************/
- static char *monthTab[13] = {"", "Jan", "Feb", "Mar",
- "Apr", "May", "Jun",
- "Jul", "Aug", "Sep",
- "Oct", "Nov", "Dec" };
- FILE *upfd;
- int acount;
- int byteRate; /* Bytes/sec that modem is set for. */
-
- #define AUDIT 9000
- char audit[AUDIT];
-
- /************************************************************************/
- /* External variable definitions for MISC.C */
- /************************************************************************/
- extern struct config cfg; /* Lots an lots of variables */
- extern struct logBuffer logBuf; /* Person buffer */
- extern struct aRoom roomBuf; /* Room buffer */
- extern struct rTable roomTab[];
- extern struct msgB msgBuf;
- extern unsigned char termNulls; /* How many nulls? */
- extern unsigned char termWidth; /* How many columns? */
- extern char termUpper; /* Upper only? */
- extern char termLF; /* Linefeeds? */
- extern char expert; /* expert? */
- extern char aide; /* aide? */
- extern char sendTime; /* Show time message created? */
- extern unsigned char crtColumn; /* where are we on screen now? */
- extern char loggedIn; /* Is we logged in? */
- extern char outFlag; /* Output flag */
- extern char haveCarrier; /* Do we still got carrier? */
- extern char usingWCprotocol;/* WC flag */
- extern char prevChar; /* previous char output */
- extern char textDownload; /* flag */
- extern char whichIO; /* Where I/O is */
- extern char echo; /* Should we echo? echo? echo? */
- extern FILE *msgfl;
- extern FILE *roomfl;
- extern FILE *logfl;
- extern char oldToo;
- extern int exitValue;
-
- /************************************************************************/
- /* External function definitions for MISC.C */
- /************************************************************************/
- char mAbort();
- FILE *fopen();
-
- /************************************************************************/
- /* changedate() gets the date from the aide and remembers it */
- /************************************************************************/
- changeDate()
- {
- int year, day, hours, minutes;
- char *month;
-
- getdate(&year, &month, &day, &hours, &minutes);
- mPrintf("Current date is: %d%s%02d\n ", year, month, day);
- mPrintf("Current time is: %d:%02d\n ", hours, minutes);
- if (!getYesNo("Enter a new date & time"))
- return ;
- setdate();
- }
-
- /************************************************************************/
- /* configure() sets up terminal width etc via dialogue */
- /************************************************************************/
- configure(showVals)
- char showVals;
- {
- if (showVals && loggedIn) {
- mPrintf("\n Your current setup:\n ");
- mPrintf("%s, ", (expert) ? "Expert" : "Non-expert");
-
- mPrintf("%s,\n %slinefeeds, %d nulls,",
- termUpper ? "UPPERCASE ONLY" : "Upper and Lower case",
- termLF ? "" : "no ",
- termNulls
- );
- mPrintf(" screen width is %d\n ", termWidth);
- mPrintf("%s time messages created,\n ",
- sendTime ? "Print" : "Do not print");
- mPrintf("%s last Old message on <N>ew Message request.",
- oldToo ? "Print" : "Do not print");
- mPrintf("\n ");
- if (!getYesNo("Reset your configuration")) return;
- }
-
- mPrintf("\n ");
- termWidth = getNumber(" Screen width", 10, 255);
- termNulls = getNumber(" #Nulls", 0, 255);
- termUpper =!getYesNo(" Do you have lower case" ) ? TRUE : FALSE;
- termLF = getYesNo(" Do you need Linefeeds" ) ? TRUE : FALSE;
- expert =!getYesNo(" Do you want Helpful Hints" ) ? TRUE : FALSE;
- sendTime = getYesNo(" Print time messages created") ? TRUE : FALSE;
- oldToo = getYesNo(" Print last Old message on <N>ew Message request")
- ? TRUE : FALSE;
-
- /* Now make it (only) semi-permanent --JLS&HAW */
- logBuf.lbwidth = termWidth;
- logBuf.lbnulls = termNulls;
- logBuf.lbflags.EXPERT = expert;
- logBuf.lbflags.UCMASK = termUpper;
- logBuf.lbflags.LFMASK = termLF;
- logBuf.lbflags.AIDE = aide;
- logBuf.lbflags.TIME = sendTime;
- logBuf.lbflags.OLDTOO = oldToo;
- }
-
- /************************************************************************/
- /* crashout() Problems? Out we go!!! */
- /************************************************************************/
- crashout(message)
- char *message;
- {
- FILE *fd; /* Record some crash data */
- int i;
-
- exitValue = CRASH_EXIT;
- outFlag = IMPERVIOUS;
- mPrintf("\n Whoops!! CRASHOLA!! Thanks and bye, leave mail on Test Sys!\n ");
- printf("STATUS:\nmsgfl %d\nlogfl %d\nroomfl %d\n",
- ferror(msgfl), ferror(logfl), ferror(roomfl));
- interpret(cfg.pHangUp);
- fclose(msgfl);
- fclose(roomfl);
- fclose(logfl);
- fd = fopen("crash", "w");
- fprintf(fd, message);
- fclose(fd);
- fd = fopen("audit", "w");
- for (i = 0; i < AUDIT; i++) {
- fputc(audit[i], fd);
- if ((i+1) % 70 == 0) fprintf(fd, "\n");
- }
- fprintf(fd, "\n\ncounter = %d\n", acount);
- fclose(fd);
- writeSysTab();
- exit(exitValue);
- }
-
- /************************************************************************/
- /* doCR() does a newline on modem and console */
- /************************************************************************/
- doCR()
- {
- int i;
-
- crtColumn = 1;
- if (outFlag != OUTOK && /* output is being s(kip)ped */
- outFlag != IMPERVIOUS)
- return;
-
- mputChar(NEWLINE);
- if (haveCarrier) {
- if (!usingWCprotocol) {
- outMod('\r');
- for (i = termNulls; i; i--) outMod(0);
- if (termLF) outMod('\n');
- } else {
- sendWCChar('\r');
- if (termLF) sendWCChar('\n');
- }
- }
- prevChar = ' ';
- }
-
- /************************************************************************/
- /* download() is the menu-level send-message-via-WC-protocol fn */
- /************************************************************************/
- download(whichMess, revOrder)
- char whichMess, revOrder;
- {
- outFlag = OUTOK;
- if (!expert) tutorial("wcdown.blb");
-
- if (!getYesNo("Ready")) return;
-
- /* here we go: */
- echo = NEITHER;
- usingWCprotocol = TRUE ; /* all points bulletin */
-
- if (doWC(STARTUP)) {
-
- showMessages(whichMess, revOrder);
-
- doWC(FINISH);
-
- }
-
- setUp(FALSE);
- usingWCprotocol = FALSE ;
- }
-
- /************************************************************************/
- /* getdate() retrieves system date and returns in the parameters */
- /************************************************************************/
- getdate(year, month, day, hours, minutes)
- int *year, *day, *hours, *minutes;
- char **month;
- {
- #ifdef MSDOS
- struct regval s;
-
- s.ax = 0x2a00;
- sysint21(&s, &s);
- *year = s.cx - 1900;
- *month = monthTab[(s.dx & 0xff00) >> 8];
- *day = (s.dx & 0x00ff);
- s.ax = 0x2c00;
- sysint21(&s, &s);
- *hours = (s.cx & 0xff00) >> 8;
- *minutes = s.cx & 0x00ff;
- #else
- *year = interpret(pGetYear);
- *month = interpret(pGetMonth);
- *day = interpret(pGetDay);
- *hours = *minutes = 0;
- #endif
- }
-
- #ifdef XYZZY
- /************************************************************************/
- /* patchDebug() */
- /************************************************************************/
- patchDebug() {
- unsigned i, j, page;
- char finished, *pc;
-
- mPrintf("\bpatch\n ");
- page = getNumber("page", 0, 255);
- finished = FALSE;
- do {
- for (i=16, pc= (page*256); i; i--) {
- mPrintf("%d ", pc);
- for (j=16; j; j--) {
- mPrintf("%c", visible(*pc++));
- }
- mPrintf("\n ");
- }
- switch (toLower(iChar())) {
- case 'r':
- pc = getNumber("adr", 0, 65355);
- *pc = getNumber("val", 0, 255);
- break;
- case 'n': page++; break;
- case 'p': page--; break;
- default: finished = TRUE; break;
- }
- } while (!finished);
- }
- #endif
- /************************************************************************/
- /* printDate() prints out current date. */
- /************************************************************************/
- printDate()
- {
- int day, year, h, m;
- char *month;
-
- getdate(&year, &month, &day, &h, &m);
- mPrintf("%d%s%02d ", year, month, day);
- }
-
- /************************************************************************/
- /* putFLChar() is used to upload files */
- /* returns: ERROR on problems else TRUE */
- /************************************************************************/
- putFLChar(c)
- char c;
- {
- if (fputc(c, upfd) != EOF) return TRUE;
- /* else */ printf("Write error: %d\n", ferror(upfd));
- return ERROR;
- }
-
- /************************************************************************/
- /* putWCChar() filter[]s from readFile() to putMsgChar() */
- /* Returns: ERROR if problems, else TRUE */
- /* Globals: outFlag is set to OUTSKIP when an ascii EOF (^Z) is */
- /* encountered, and no further text is written to disk. */
- /************************************************************************/
- int putWCChar(c)
- int c;
- {
- if (outFlag) return TRUE; /* past ascii EOF. ignore. */
-
- if (c == ERROR) {
- /* EOF. Note for overkill: */
- outFlag = OUTSKIP;
- return TRUE;
- }
-
- c &= 0x7F; /* cut high stuff off */
-
- if (c == CPMEOF) {
- /* ascii EOF. Ignore rest of file: */
- outFlag = OUTSKIP;
- return TRUE;
- }
-
- return putMsgChar(cfg.filter[c]);
- }
-
- /************************************************************************/
- /* setdate() Sets the date. */
- /************************************************************************/
- setdate()
- {
- #ifdef MSDOS
- struct regval s;
-
- while (1) {
- s.cx = getNumber("Year", 85, 99) + 1900;
- s.dx = getNumber("Month", 1, 12) << 8 ;
- s.dx += getNumber("Day", 1, 31) ;
- s.ax = 0x2b00;
- sysint21(&s, &s);
- if (s.ax & 0xff)
- mPrintf("Invalid date\n ");
- else
- break;
- }
- while (1) {
- s.cx = getNumber("Hour", 0, 23) << 8;
- s.cx += getNumber("Minute", 0, 59) ;
- s.dx = 0;
- s.ax = 0x2d00;
- sysint21(&s, &s);
- if (s.ax & 0xff)
- mPrintf("Invalid time\n ");
- else
- break;
- }
- #else
- interpret(pInitDate);
- #endif
- }
-
- /************************************************************************/
- /* transmitFile() dumps a host file with no formatting */
- /************************************************************************/
- transmitFile(filename)
- char *filename;
- {
- #define CPMEOF 26 /* For CP/M files, EOF == ^Z */
- int getc(), sendWCChar();
- char fname[NAMESIZE];
- long fseek(), totalSectors, fileSize;
- long Secs, Mins, totalTime, totalBytes;
- FILE *fbuf;
- int c;
-
- outFlag = OUTOK;
-
- unspace(filename, fname);
-
- if ((fbuf = fopen(fname, "rb")) == NULL) {
- usingWCprotocol = FALSE;
- mPrintf("\n No %s.\n", fname);
- return(ERROR);
- }
-
- doCR();
- if (usingWCprotocol) {
- usingWCprotocol = FALSE;
- if (byteRate != 0) {
- fileSize = fseek(fbuf, -1l, 2) + 1;
- rewind(fbuf);
- totalSectors = ((fileSize + 127) / fileSize);
- totalBytes = fileSize + (totalSectors * 5);
- totalTime = totalBytes/byteRate; /* In seconds */
- Mins = totalTime / 60;
- Secs = totalTime % 60;
- mPrintf(
- "\n Total time to download '%s' should be about %ld:%02ld minutes",
- fname, Mins, Secs);
- }
-
- if (!getYesNo("Ready for WC transfer")) {
- fclose(fbuf);
- return ERROR;
- }
- usingWCprotocol = TRUE;
- if (!doWC(STARTUP)) {
- fclose(fbuf);
- return ERROR;
- }
- }
-
- while ((c = getc(fbuf)) != ERROR && (c != CPMEOF || !textDownload)) {
- if (!usingWCprotocol) {
- mputChar(c);
- if (interpret(cfg.pCarrDetect)) outMod(c);
- }
- else if (!sendWCChar(c)) break;
- if (!usingWCprotocol && mAbort()) break;
- if (whichIO == MODEM && !gotCarrier()) break;
- }
-
- if (usingWCprotocol) doWC(FINISH);
-
- fclose(fbuf);
- }
-
- /************************************************************************/
- /* tutorial() prints file <filename> on the modem & console */
- /* Returns: TRUE on success else ERROR */
- /************************************************************************/
- #define MAXWORD 256
- tutorial(filename)
- char *filename;
- {
- FILE *fbuf;
- char line[MAXWORD];
- int toReturn;
-
- toReturn = TRUE;
-
- outFlag = OUTOK;
- if (filename[1] == ':' || (fbuf = fopen(filename, "r")) == NULL) {
- mPrintf("\n No %s.\n", filename);
- toReturn = ERROR;
- } else {
- if (!expert) mPrintf("\n <J>ump <P>ause <S>top\n");
- mPrintf(" \n");
- while (fgets(line, MAXWORD, fbuf)) mPrintf("%s", line);
- fclose(fbuf);
- }
-
- return toReturn;
- }
-
- /************************************************************************/
- /* upLoad() enters a file into current directory */
- /************************************************************************/
- upLoad()
- {
- char fileName[NAMESIZE], *s;
- int putFLChar();
- char successful;
-
- getNormStr("filename", fileName, NAMESIZE, ECHO);
-
- if (fileName[1] != ':') s = &fileName[0];
- else s = &fileName[2];
-
- if (!setSpace(roomBuf.rbdisk, roomBuf.rbdirname)) {
- crashout("ERROR: DIRECTORY NOT FOUND!");
- }
-
- if ((upfd = fopen(s, "r")) != NULL) {
- mPrintf("\n A %s already exists.\n", s);
- fclose(upfd);
- } else {
- if (!expert) {
- if (strLen(roomBuf.rbdirname) != 0) setSpace(roomBuf.rbdisk, "..");
- setSpace(cfg.homeDisk, "");
- tutorial("wcupload.blb");
- setSpace(roomBuf.rbdisk, roomBuf.rbdirname);
- }
- if ((upfd = fopen(s, "wb")) == NULL) {
- mPrintf("\n Can't create %s!\n", s);
- } else {
- if (!getYesNo("Ready for WC transfer"))
- successful = FALSE;
- else
- successful = readFile(putFLChar);
- fclose(upfd);
- if (!successful) unlink(s);
- else {
- sPrintf(msgBuf.mbtext, "File \"%s\" uploaded into %s by %s.",
- s, roomBuf.rbname, logBuf.lbname);
- aideMessage(FALSE);
- }
- }
- }
- if (strLen(roomBuf.rbdirname) != 0) setSpace(roomBuf.rbdisk, "..");
- setSpace(cfg.homeDisk, "");
- }
-
- /************************************************************************/
- /* visible() converts given char to printable form if nonprinting */
- /************************************************************************/
- char visible(c)
- unsigned char c;
- {
- if (c==0xFF) c = '$' ; /* start-of-message in message.buf */
- c = c & 0x7F ; /* kill high bit otherwise */
- if ( c < ' ') c = c + 'A' -1; /* make all control chars letters */
- if (c== 0x7F) c = '~' ; /* catch DELETE too */
- return(c);
- }
-